export function useSetNotifications() {
    const id = "notification1"
    let progress = 0
    browser.notifications.create(id, {
        type: "progress",
        title: "Primary Title",
        message: "Primary message to display",
        iconUrl: browser.runtime.getURL("/icon/32.png"),
        buttons: [{
            title: "OK",
        }, {
            title: "OFF",
        }],
        progress
    })

    const time = setInterval(() => {
        progress++;
        browser.notifications.update(
            id, {
                progress
            }
        )
    }, 1000)

    function replyBtnClick(notificationId: string, buttonIndex: number) {
        if(buttonIndex===1){
            browser.notifications.clear(notificationId)
        }
    }

    function onClosed() {
        progress = 0;
        clearInterval(time)
    }

    browser.notifications.onButtonClicked.addListener(replyBtnClick);
    browser.notifications.onClosed.addListener(onClosed);
}